window.onload = function() {
    let username = document.getElementById("username")
    let password = document.getElementById("password")
    console.log(username.value)
    username.addEventListener("input", (e) => {
            console.log(e.target.value)
        })
    let btn = document.querySelector("button")
    btn.addEventListener("click", (e) => {
        let name = username.value
        let passd = password.value
        let promise = new Promise((resolve, reject) => {
            let data  = {
                username: name,
                password: passd
            }
            let xhr = new XMLHttpRequest()
            xhr.open("GET", "http://172.19.14.60:8080/login" + "?username=" + name + '&password=' + passd, true)
            xhr.setRequestHeader("Content-Type", "application/json")
            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    console.log("请求成功")
                    resolve(xhr.responseText)
                }
            }

            xhr.send()
            setTimeout(() => {
                console.log("等待2秒")
                resolve("输出成功")
            }, 2000)
        })
        promise.then((e) => {
            console.log(e)
            console.log("成功")
        }).catch(() => {
            console.log("失败")
        }).finally(() => {
            console.log("成功失败都会执行")
        })
    })
}